package org.example;

import org.apache.kafka.clients.admin.*;
import org.apache.kafka.common.errors.TopicExistsException;

import java.util.Collections;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

/**
 *@description: 删除主题
 *@author: xukang
 *@create: 2025-05-30
 */
public class DelTopicExample {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");

        try (AdminClient adminClient = AdminClient.create(props)) {
            // 构建主题配置
            DeleteTopicsResult result = adminClient.deleteTopics(Collections.singletonList("my-topic"));
            // 等待创建完成
            result.all().get();
            System.out.println("主题删除成功");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
